/*
 * @Author: wyf 844650674@qq.com
 * @Date: 2022-10-12 08:30:48
 * @LastEditors: wangyifei 844650674@qq.com
 * @LastEditTime: 2022-11-27 13:58:07
 * @FilePath: \sports\admin-server\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const express = require('express')
const errorHandle = require('./middleware/error')
require('./model')
const cors= require('cors')
var https = require('https');
var http = require('http');

const app = express()
app.use((req, res, next) => {
	res.header('Access-Control-Allow-Origin', '*')
	res.header('Access-Control-Allow-Headers', 'Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method' )
	res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PATCH, PUT, DELETE')
	res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE')
	next();
});
const router = require('./router')
app.use(express.json())
app.use(cors())
app.use('/uploads', express.static(__dirname + '/uploads'))
app.use('/admin', express.static(__dirname + '/admin'))
app.use('/', express.static(__dirname + '/web'))

// 挂载路由
app.use('', router)

// 通用增删改查
require('./router/common')(app)

// 挂载同意处理的服务的错误
app.use(errorHandle())

app.listen('3000', () => {
	console.log('后台服务启动成功')
})